package com.ruoyi.expert.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.expert.mapper.Expertmapper;
import com.ruoyi.expert.pojo.*;
import com.ruoyi.expert.pojo.vo.ExpertVO;
import com.ruoyi.expert.service.Expertservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 参数配置 服务层实现
 * @author wyp
 */
@Service
public class Expertserviceimpl implements Expertservice {
    @Autowired
    private Expertmapper mapper;
    @Override
    public List<DtExpert> selectExpert(CsExpert csExpert) {
        // 执行查询，返回的是结果列表
        List<DtExpert> experts = mapper.selectExpert(csExpert);
        return experts;
    }
    @Override
    public List<Expert> selectExpert01(Expert expert) {
        return mapper.selectExpert01(expert);
    }

    @Override
    public List<Experience> selectExperience(Experience experience) {
        return mapper.selectExperience(experience);
    }

    @Override
    public List<Educate> selectEducate(Educate educate) {
        return mapper.selectEducate(educate);
    }

    @Override
    public List<Training> selectTraining(Training training) {
        return mapper.selectTraining(training);
    }

    @Override
    public List<Occupation> selectOccupation(Occupation occupation) {
        return mapper.selectOccupation(occupation);
    }

    @Override
    public List<Job> selectJob(Job job) {
        return mapper.selectJob(job);
    }

    @Override
    public Integer updateExpert(Expert expert) {
        return mapper.updateExpert(expert);
    }

    @Override
    public List<ExpertVO> getDialogExpertData(CsExpert csExpert) {
        List<ExpertVO> dialogExpertData = mapper.getDialogExpertData(csExpert);
        for (ExpertVO ss: dialogExpertData ) {
            System.out.println("ss = " + ss);
        }
        Map<String, ExpertVO> mergedMap =new HashMap<>();
        if (dialogExpertData!=null&&dialogExpertData.size()>0){
            mergedMap= dialogExpertData.stream()
                    .collect(Collectors.toMap(
                            ExpertVO::getIdCard, // 使用身份证号作为键
                            p -> p, // 值是 Person 对象
                            (p1, p2) -> {
                                p1.getProfession().addAll(p2.getProfession()); // 合并职业
                                return p1;
                            }
                    ));
        }
        List<ExpertVO> newRes = new ArrayList<>(mergedMap.values());
        return newRes;
    }
}
